/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package au.edu.swin.bank.persistence.entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Luke Horvat
 */
@Entity
@Table(name = "BILLPAYMENT")
@NamedQueries({
    @NamedQuery(name = "BillPayment.findAll", query = "SELECT b FROM BillPayment b"),
    @NamedQuery(name = "BillPayment.findByDate", query = "SELECT b FROM BillPayment b WHERE b.billPaymentPK.date = :date"),
    @NamedQuery(name = "BillPayment.findByBillid", query = "SELECT b FROM BillPayment b WHERE b.billPaymentPK.billid = :billid"),
    @NamedQuery(name = "BillPayment.findByAmount", query = "SELECT b FROM BillPayment b WHERE b.amount = :amount")})
public class BillPayment implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected BillPaymentPK billPaymentPK;
    @Column(name = "AMOUNT")
    private Double amount;
    @JoinColumn(name = "BILLID", referencedColumnName = "BILLID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Bill bill;
    @JoinColumn(name = "CUSTOMERACCOUNTID", referencedColumnName = "ACCOUNTID")
    @ManyToOne
    private Account account;

    public BillPayment() {
    }

    public BillPayment(BillPaymentPK billPaymentPK) {
        this.billPaymentPK = billPaymentPK;
    }

    public BillPayment(BigInteger date, BigInteger billid) {
        this.billPaymentPK = new BillPaymentPK(date, billid);
    }

    public BillPaymentPK getBillPaymentPK() {
        return billPaymentPK;
    }

    public void setBillPaymentPK(BillPaymentPK billPaymentPK) {
        this.billPaymentPK = billPaymentPK;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Bill getBill() {
        return bill;
    }

    public void setBill(Bill bill) {
        this.bill = bill;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (billPaymentPK != null ? billPaymentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BillPayment)) {
            return false;
        }
        BillPayment other = (BillPayment) object;
        if ((this.billPaymentPK == null && other.billPaymentPK != null) || (this.billPaymentPK != null && !this.billPaymentPK.equals(other.billPaymentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "au.edu.swin.bank.persistence.entity.BillPayment[billPaymentPK=" + billPaymentPK + "]";
    }

}
